package io.gitee.hchaojie.day04;

import java.util.Timer;
import java.util.TimerTask;

public class DemoTimer2 {
    int j = 1;

    public static void main(String[] args) {
        Timer timer = new Timer();

        // DemoTimer2 out = new DemoTimer2();

        timer.schedule(new DemoTimer2().new CountTask(), 0, 1000);
        // timer.schedule(new CountTask(), 1000, 2000);
    }

    public void count() {
        this.j++;
    }

    class CountTask extends TimerTask {
        int j = 10;

        public void count() {
            this.j++;
        }

        @Override
        public void run() {
            // System.out.println("count: " + j++);
            // count();
            System.out.println("count: " + this.j++);
            System.out.println("count: " + DemoTimer2.this.j++);
            DemoTimer2.this.count();    // 调用外部类的同名方法
        }
    }
}

